var nodeDs;
var nodeForm; 
Ext.onReady(function(){ 

	
	var sm = new Ext.grid.CheckboxSelectionModel({singleSelect: true});	
	var recordType = Ext.data.Record.create([								
                			   {name: 'id', type: "string"},
                			   {name: 'outOrder', type: "string"},
							   {name: 'ocid', type: "string"},
                	           {name: 'ocName', type: "string"},
                	           {name: 'poleNum', type: "string"},
							   {name: 'propertyRight', type: "string"},
							   {name: 'longleath1', type: "string"},
                	           {name: 'longleath2', type: "string"},
							   {name: 'lng', type: "string"},
							   {name: 'lat', type: "string"},
							   {name: 'distance', type: "string"},
							   {name: 'isNode', type: "string"},
							   {name: 'isJoint', type: "string"},
							   {name: 'isRes', type: "string"},
							   {name: 'resLength', type: "string"},
							   {name: 'granularity', type: "string"},
							   {name: 'updateTime', type: "string"},
							   {name: 'ocLayType', type: "string"},
							   {name: 'routeInfo', type: "string"}
                	     ]);

	var cm  = new Ext.grid.ColumnModel(
			[
				sm,	            
				{header: "序号", width: 40, sortable: true, dataIndex: 'outOrder',align:'left'},
	            {header: "中继段名称", width: 100, sortable: true, dataIndex: 'ocName',align:'left'},
	            {header: "杆号", width: 50, sortable: true, dataIndex: 'poleNum',align:'left'},
				{header: "经度", width: 70, sortable: true, dataIndex: 'lng',align:'left'},
				{header: "纬度", width: 70, sortable: true, dataIndex: 'lat',align:'left'},
	            {header: "与前一节点长度", width: 100, sortable: true, dataIndex: 'distance',align:'left'}, 
				{header: "接头", width: 50, sortable: true,renderer: formatIsNode, dataIndex: 'isJoint',align:'left'}, 	
				{header: "预留长度", width: 100, sortable: true, dataIndex: 'resLength',align:'left'},
				{header: "本点累加长度", width: 100, sortable: true, dataIndex: 'granularity',align:'left'}				
			]
		);
	function formatIsNode(value)
	{	
		if(value == '0')
			return "<span style='color:red;font-weight:bold;'>否</span>";
		else
			return "<span style='color:green;font-weight:bold;'>是</span>";
	}
		

	nodeDs = new Ext.data.Store({
        proxy: new Ext.data.DWRProxy(JFiberWeb.getSectionOutInfoList, true),	
        reader: new Ext.data.ListRangeReader({
            totalProperty: 'totalSize',
            id: 'id'
        }, recordType),
        sortInfo:{field:'id', direction:'ASC'}// 排序信息
    });


	
	var sectionGrid = new Ext.grid.GridPanel({
	    	region : 'center',	    	
	        ds: nodeDs,
	        cm: cm,
			sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) { 
                            nodeForm.getForm().loadRecord(rec);
                        }
                    }
                }),
			//title: '(<%=strName%>)', 
			height: 400,
			minSize: 200,
	        frame:true,
	        collapsible:false, 
	        enableDragDrop:false,   
			autoExpandColumn:2, 
			tbar: [
					'查询: ', ' ',
					new Ext.ux.form.SearchField({
						store:nodeDs,
						width:320
					})],
			bbar: new Ext.PagingToolbar({
			        pageSize: 17,
			        store: nodeDs,
			        displayInfo: true,
			        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			        emptyMsg: "没有记录"
			    })					
				
	    });
	nodeDs.on('beforeload', function() {
			  nodeDs.baseParams = {
					queryType:'isNode'   
			  };
		});		
		
	var isResData = [['0', '否'],['1', '是']];
        
	var isResStore = new Ext.data.SimpleStore({
		    fields: ['id', 'text'],
		    data : isResData
		});
	
	var isNodeCombox = new Ext.form.ComboBox({	   
	        fieldLabel: '是否为节点',
	        name: 'isNode',	
	       	width:135,
	        valueField :"id",
	        displayField: "text",
	        mode: 'local',
	        selectOnFocus:true,                    
	        forceSelection: true,
	        hiddenName:'isNode',
	        triggerAction: 'all',
	        editable:false, 
	        allowBlank:false,
			disabled:true,
	        blankText :'请选是否为节点',
	        store: isResStore,
	        value:0
		});	
	var isResCombox = new Ext.form.ComboBox({	   
	        fieldLabel: '是否预留',
	        name: 'isRes',	
	       	width:135,
	        valueField :"id",
	        displayField: "text",
	        mode: 'local',
	        selectOnFocus:true,                    
	        forceSelection: true,
	        hiddenName:'isRes',
	        triggerAction: 'all',
	        editable:false, 
	        allowBlank:false,
	        blankText :'请选是否预留',
			disabled:true,
	        store: isResStore,
	        value:0
		});
	var isJointCombox = new Ext.form.ComboBox({	   
	        fieldLabel: '是否是接头',
	        name: 'isJoint',	
	       	width:135,
	        valueField :"id",
	        displayField: "text",
	        mode: 'local',
	        selectOnFocus:true,                    
	        forceSelection: true,
	        hiddenName:'isJoint',
	        triggerAction: 'all',
	        editable:false, 
	        allowBlank:false,
	        blankText :'请选是否是接头',
	        store: isResStore,
			disabled:true,
	        value:0
		});	
		
	isResCombox.addListener("select",function(){		 
			if(isResCombox.value == 1)
				resLengthText.enable();
			else
				resLengthText.disable();
		});
	isJointCombox.addListener("select",function(){		 
			if(isJointCombox.value == 1)
				ocLayTypeCombox.enable();
			else
				ocLayTypeCombox.disable();
		});	
		
	resLengthText = new Ext.form.NumberField({ 
				xtype:'numberfield',
				allowDecimals: true, 
				fieldLabel : '预留长度', 
				value:0,
				name : 'resLength'
			}); 
	resLengthText.disable();
 
 
	var ocLayTypeData = [['0', '电杆'],['1', '管道'],['1', '直埋']];
	var ocLayTypeStore = new Ext.data.SimpleStore({
		    fields: ['id', 'text'],
		    data : ocLayTypeData
		});
	
	var ocLayTypeCombox = new Ext.form.ComboBox({	   
	        fieldLabel: '敷设方式',
	        name: 'ocLayType',	
	       	width:135,
	        valueField :"id",
	        displayField: "text",
	        mode: 'local',
	        selectOnFocus:true,                    
	        forceSelection: true,
	        hiddenName:'ocLayType',
	        triggerAction: 'all',
	        editable:false, 
			disabled:true,
	        store: ocLayTypeStore,
	        value:0
		}); 
	ocLayTypeCombox.disable();	
		
	nodeForm = new Ext.form.FormPanel({
		region     : 'east', 
		labelWidth: 95,
        frame:true,
        title: '总体信息', 
        width: 300,
		height:450,
        defaults: {width: 180},
        defaultType: 'textfield',
		items: [
				{
					xtype : 'hidden',
					name: 'id'
				},
				{
					xtype : 'hidden',
					name: 'ocid'
				},{
					fieldLabel: '中继段名称',
					name: 'ocName', 
					readOnly:true,
					disabled:true,
					value:'<%=strName%>' 	
				},{
					fieldLabel: '杆号',
					name: 'poleNum',
					readOnly:true,
					disabled:true,
					blankText :'请输入杆号'	
				},{
					fieldLabel: '产权',
					name: 'propertyRight',
					readOnly:true,
					disabled:true,
					blankText :'请输入产权'	
				},
				{
					xtype:'numberfield',
					allowDecimals: true, 
					disabled:true,
					fieldLabel: '本点皮长',
					readOnly:true,
					name: 'longleath1'
				},{
					xtype:'numberfield',
					allowDecimals: true, 
					disabled:true,
					fieldLabel: '本点皮长',
					readOnly:true,
					name: 'longleath2'
				},{
					xtype:'numberfield',
					allowDecimals: true, 
					decimalPrecision:5,
					fieldLabel: '经度',
					name: 'lng',
					readOnly:true,
					disabled:true,
					blankText :'请输入经度'	
				},{
					xtype:'numberfield',
					allowDecimals: true, 
					decimalPrecision:5,
					fieldLabel: '维度',
					name: 'lat',
					readOnly:true,
					disabled:true,
					blankText :'请输入维度'	
				},{
					xtype:'numberfield',
					allowDecimals: true, 
					fieldLabel: '与前一节点长度',
					name: 'distance',
					readOnly:true,
					disabled:true,
					blankText :'请输入与前一节点长度'	
				},
				isNodeCombox,
				isResCombox,
				resLengthText,
				isJointCombox,
				ocLayTypeCombox,
				{
					fieldLabel: '路由信息',
					readOnly:true,
					disabled:true,
					name: 'routeInfo'
				}
				
        ],
        buttons: [
				{
					text: '后退',
					handler:function()
					{
						history.go(-1);
					}
				}]
	})


	var displayPanel = new Ext.Panel({
		width    : mainTabPanelDIV.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'nodeTab',
		items    : [
			sectionGrid,
			nodeForm
		]
	});	
	
	loadDateOther(nodeDs,nodeForm,"isNode");
})	
	


